home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / apport / package_hook < prev   
Encoding:
Text File  |  2009-09-25  |  1.8 KB  |  59 lines

  1. #!/usr/bin/python
  2. #
  3. # Collect information about a package installation/upgrade failure.
  4. #
  5. # Copyright (c) 2007 Canonical Ltd.
  6. # Author: Martin Pitt <martin.pitt@ubuntu.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify it
  9. # under the terms of the GNU General Public License as published by the
  10. # Free Software Foundation; either version 2 of the License, or (at your
  11. # option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
  12. # the full text of the license.
  13.  
  14. import sys, optparse, os.path, os
  15. import apport, apport.fileutils
  16.  
  17. def mkattrname(path):
  18.     '''Convert a file path to a problem report attribute name.'''
  19.  
  20.     name = ''
  21.     for dir in path.split(os.sep):
  22.     if dir:
  23.         name += ''.join([c for c in dir[0].upper() + dir[1:] if c.isalnum()])
  24.     return name
  25.     
  26. #
  27. # main
  28. #
  29.  
  30. # parse command line arguments
  31. optparser = optparse.OptionParser('%prog [options]')
  32. optparser.add_option('-p', '--package', 
  33.     help='Specify the package name which failed to upgrade (mandatory)',
  34.     action='store', type='string', dest='package')
  35. optparser.add_option('-l', '--log', 
  36.     help='Append given log file, or, if it is a directory, all files in it (can be specified multiple times)',
  37.     action='append', type='string', dest='logs')
  38. options = optparser.parse_args()[0]
  39.  
  40. if not options.package:
  41.     print >> sys.stderr, 'Error: You need to specify a package name with --package'
  42.     sys.exit(1)
  43.  
  44. # create report
  45. pr = apport.Report('Package')
  46. pr['Package'] = options.package
  47. pr['SourcePackage'] = apport.packaging.get_source(options.package)
  48. pr['ErrorMessage'] = (sys.stdin, False)
  49. for l in (options.logs or []):
  50.     if os.path.isfile(l):
  51.     pr[mkattrname(l)] = (l,)
  52.     elif os.path.isdir(l):
  53.     for f in os.listdir(l):
  54.         path = os.path.join(l, f)
  55.         pr[mkattrname(path)] = (path,)
  56.  
  57. # write report
  58. pr.write(open(apport.fileutils.make_report_path(pr), 'w'))
  59.